<template>
	<view class="jnpf-wrap jnpf-wrap-workflow">
		<u-form :model="info" ref="dataForm" :errorType="['toast']" label-position="left" label-width="150"
			label-align="left">
			<u-form-item label="项目编号" v-if="judgeShow('ta001')">
				<u-input v-model="info.ta001" placeholder="项目编号" disabled></u-input>
			</u-form-item>
			<u-form-item label="项目名称" v-if="judgeShow('ta004')">
				<u-input v-model="info.ta004" placeholder="项目名称" disabled></u-input>
			</u-form-item>
			<u-form-item label="合同号" v-if="judgeShow('ta039')">
				<u-input v-model="info.ta039" placeholder="合同号" :disabled="judgeWrite('ta039')"></u-input>
			</u-form-item>
			<u-form-item label="预测单号" type="textarea" v-if="judgeShow('ta040')">
				<u-input v-model="info.ta040" placeholder="预测单号" :disabled="judgeWrite('ta040')"></u-input>
			</u-form-item>
			<u-form-item label="客户名称" type="textarea" v-if="judgeShow('ta009')">
				<view v-for="(item,index) in ta009Name" :key="index" style="margin-left: 5px;">
					<u-tag :text="item" type="success" />
				</view>
			</u-form-item>
			<u-form-item label="技术负责人" type="textarea" v-if="judgeShow('udf301')">
				<view v-for="(item,index) in udf301Name" :key="index" style="margin-left: 5px;">
					<u-tag :text="item" type="success" />
				</view>
			</u-form-item>
			<u-form-item label="业务负责人" type="textarea" v-if="judgeShow('udf302')">
				<view v-for="(item,index) in udf302Name" :key="index" style="margin-left: 5px;">
					<u-tag :text="item" type="success" />
				</view>
			</u-form-item>
			<u-form-item label="填单人" type="textarea" v-if="judgeShow('udf306')">
				<view v-for="(item,index) in udf306Name" :key="index" style="margin-left: 5px;">
					<u-tag :text="item" type="success" />
				</view>
			</u-form-item>
			<u-form-item label="制作人" type="textarea" v-if="judgeShow('udf303')">
				<view v-for="(item,index) in udf303Name" :key="index" style="margin-left: 5px;">
					<u-tag :text="item" type="success" />
				</view>
			</u-form-item>
			<u-form-item label="审核人" type="textarea" v-if="judgeShow('udf304')">
				<view v-for="(item,index) in udf304Name" :key="index" style="margin-left: 5px;">
					<u-tag :text="item" type="success" />
				</view>
			</u-form-item>
			<u-form-item label="项目经理" type="textarea" v-if="judgeShow('udf305')">
				<view v-for="(item,index) in udf305Name" :key="index" style="margin-left: 5px;">
					<u-tag :text="item" type="success" />
				</view>
			</u-form-item>
			<u-form-item label="项目分类" type="textarea" v-if="judgeShow('ta003')">
				<u-input v-model="info.ta003" placeholder="项目分类" :disabled="judgeWrite('ta003')"></u-input>
			</u-form-item>
			<u-form-item label="优先级" type="textarea" v-if="judgeShow('ta007')">
				<u-tag v-if='info.ta007==1' text="常规" type="primary" />
				<u-tag v-if='info.ta007==2' text="优先" type="warning" />
				<u-tag v-if='info.ta007==3' text="重点" type="error" />
			</u-form-item>
			<u-form-item label="营销部确认" type="textarea" v-if="judgeShow('udf300')">
				<u-tag :text="info.udf300==1?'有':'无'" :type="info.udf300==1?'primary':'error'" />
			</u-form-item>
			<u-form-item label="制作日期" type="textarea" v-if="judgeShow('udf309')">
				<u-input v-model="info.udf309" placeholder="制作日期" :disabled="judgeWrite('udf309')"></u-input>
			</u-form-item>
			<u-form-item label="下单日期" type="textarea" v-if="judgeShow('ta014')">
				<u-input v-model="info.ta014" placeholder="下单日期" :disabled="judgeWrite('ta014')"></u-input>
			</u-form-item>
			<u-form-item label="发货日期" type="textarea" v-if="judgeShow('udf307')">
				<u-input v-model="info.udf307" placeholder="下单日期" :disabled="judgeWrite('udf307')"></u-input>
			</u-form-item>
			<u-form-item label="交付日期" type="textarea" v-if="judgeShow('udf308')">
				<u-input v-model="info.udf308" placeholder="交付日期" :disabled="judgeWrite('udf308')"></u-input>
			</u-form-item>
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<view class="jnpf-table-item" style="margin-bottom: 24rpx;" v-for="(item,i) in tableField149" :key="i">
					<u-form-item label="序号">
						{{i+1}}
					</u-form-item>
					<u-form-item label="货品编码" v-if="judgeShow('tableField149-xa002')">
						<u-input v-model="item.xa002" placeholder="货品编码"
							:disabled="judgeWrite('tableField149-xa002') " />
					</u-form-item>
					<u-form-item label="货物名称" v-if="judgeShow('tableField149-xa003')">
						<u-input v-model="item.xa003" placeholder="货物名称"
							:disabled="judgeWrite('tableField149-xa003') " />
					</u-form-item>
					<u-form-item label="规格" v-if="judgeShow('tableField149-xa004')">
						<u-input v-model="item.xa004" placeholder="规格" :disabled="judgeWrite('tableField149-xa004') " />
					</u-form-item>
					<u-form-item label="单位" v-if="judgeShow('tableField149-xa005')">
						<u-input v-model="item.xa005" placeholder="单位" :disabled="judgeWrite('tableField149-xa005') " />
					</u-form-item>
					<u-form-item label="数量" v-if="judgeShow('tableField149-xa006')">
						<u-input v-model="item.xa006" placeholder="数量" :disabled="judgeWrite('tableField149-xa006') " />
					</u-form-item>
					<u-form-item label="备注" v-if="judgeShow('tableField149-xa007')">
						<u-input v-model="item.xa007" placeholder="备注" :disabled="judgeWrite('tableField149-xa007') " />
					</u-form-item>
				</view>
			</view>
			<u-form-item label="售前方案" v-if="judgeShow('annex01')">
				<jnpf-file v-model="info.annex01" :disabled="judgeWrite('annex01')" />
			</u-form-item>
			<u-form-item label="技术协议" v-if="judgeShow('annex02')">
				<jnpf-file v-model="info.annex02" :disabled="judgeWrite('annex02')" />
			</u-form-item>
			<u-form-item label="图纸" v-if="judgeShow('annex03')">
				<jnpf-file v-model="info.annex03" :disabled="judgeWrite('annex03')" />
			</u-form-item>
			<u-form-item label="附件" v-if="judgeShow('annex04')">
				<jnpf-file v-model="info.annex04" :disabled="judgeWrite('annex04')" />
			</u-form-item>
			<u-form-item label="合同纪要" v-if="judgeShow('annex05')">
				<jnpf-file v-model="info.annex05" :disabled="judgeWrite('annex05')" />
			</u-form-item>
			<u-form-item label="项目地点" type="textarea" v-if="judgeShow('udf313')">
				<u-input v-model="info.udf313" placeholder="项目地点" :disabled="judgeWrite('udf313')"></u-input>
			</u-form-item>
			<u-form-item label="施工地点" type="textarea" v-if="judgeShow('ta011')">
				<u-input v-model="info.ta011" placeholder="施工地点" :disabled="judgeWrite('ta011')"></u-input>
			</u-form-item>
			<u-form-item label="项目背景与目的" type="textarea" v-if="judgeShow('udf314')">
				<u-input v-model="info.udf314" placeholder="项目背景与目的" :disabled="judgeWrite('udf314')"></u-input>
			</u-form-item>
			<u-form-item label="项目目标" type="textarea" v-if="judgeShow('udf315')">
				<u-input v-model="info.udf315" placeholder="项目目标" :disabled="judgeWrite('udf315')"></u-input>
			</u-form-item>
			<u-form-item label="评价标准" type="textarea" v-if="judgeShow('udf316')">
				<u-input v-model="info.udf316" placeholder="评价标准" :disabled="judgeWrite('udf316')"></u-input>
			</u-form-item>
			<u-form-item label="项目假定与约束条件" type="textarea" v-if="judgeShow('udf317')">
				<u-input v-model="info.udf317" placeholder="项目假定与约束条件" :disabled="judgeWrite('udf317')"></u-input>
			</u-form-item>
			<u-form-item label="会议纪要" type="textarea" v-if="judgeShow('udf318')">
				<u-input v-model="info.udf318" placeholder="会议纪要" :disabled="judgeWrite('udf318')"></u-input>
			</u-form-item>
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<view class="jnpf-table-item" style="margin-bottom: 24rpx;" v-for="(item,i) in tableField158" :key="i">
					<u-form-item label="序号">
						{{i+1}}
					</u-form-item>
					<u-form-item label="部门" v-if="judgeShow('tableField158-xb003')">
						<u-input v-model="item.xb003" placeholder="部门" :disabled="judgeWrite('tableField158-xb003') " />
					</u-form-item>
					<u-form-item label="负责人" v-if="judgeShow('tableField158-xb004')">
						<u-input v-model="item.xb004" placeholder="负责人"
							:disabled="judgeWrite('tableField158-xb004') " />
					</u-form-item>
					<u-form-item label="协助人" v-if="judgeShow('tableField158-xb005')">
						<u-input v-model="item.xb005" placeholder="协助人"
							:disabled="judgeWrite('tableField158-xb005') " />
					</u-form-item>
					<u-form-item label="备注" v-if="judgeShow('tableField158-xb006')">
						<u-input v-model="item.xb006" placeholder="备注" :disabled="judgeWrite('tableField158-xb006') " />
					</u-form-item>
				</view>
			</view>
		</u-form>

	</view>
</template>

<script>
	import {
		getPjstazz
	} from '@/api/workFlow/flowEngine'
	import {
		getUserAll
	} from '@/api/common'
	import comMixin from '../mixin'
	import {
		getGoodsList,
		getCustomerList,
		Info,
		Create,
		Update
	} from '@/api/apply/order'
	export default {
		name: 'crmOrder',
		mixins: [comMixin],
		data() {
			return {
				dataForm: {},
				tableField149: [],
				tableField158: [],
				info: {},
				id: '',
				ta009Name: [],
				udf301Name: [],
				udf302Name: [],
				udf306Name: [],
				udf303Name: [],
				udf304Name: [],
				udf305Name: [],
			}
		},

		methods: {
			init(data, id, flowFormContentJson) {
				this.setting = data
				this.id = id
				this.getInfo(data)
			},
			getInfo(data) {
				getPjstazz(data.id).then(res => {
					if (res.code == 200) {
						this.info = res.data
						this.tableField149 = res.data.tableField149
						this.tableField158 = res.data.tableField158
						this.getUser()
					}
				})
			},
			getUser() {
				getUserAll().then(res => {
					this.ta009Name = res.data.filter(item => this.info.ta009.includes(item.id)).map(item => item
						.realName);
					this.udf301Name = res.data.filter(item => this.info.udf301.includes(item.id)).map(item => item
						.realName);
					this.udf302Name = res.data.filter(item => this.info.udf302.includes(item.id)).map(item => item
						.realName);
					this.udf306Name = res.data.filter(item => this.info.udf306.includes(item.id)).map(item => item
						.realName);
					this.udf303Name = res.data.filter(item => this.info.udf303.includes(item.id)).map(item => item
						.realName);
					this.udf304Name = res.data.filter(item => this.info.udf304.includes(item.id)).map(item => item
						.realName);
					this.udf305Name = res.data.filter(item => this.info.udf305.includes(item.id)).map(item => item
						.realName);
				})
			},

			selfGetInfo() {
				Info(this.setting.id).then(res => {
					this.dataForm = res.data
					if (this.dataForm.fileJson) {
						this.fileList = JSON.parse(this.dataForm.fileJson)
					}
				})
			},
			selfSubmit() {
				this.dataForm.status = this.eventType === 'submit' ? 0 : 1
				if (this.eventType === 'save') return this.selfHandleRequest()
				uni.showModal({
					title: '提示',
					content: '您确定要提交当前流程吗？',
					success: res => {
						if (res.confirm) {
							this.selfHandleRequest()
						}
					}
				})
			},
			selfHandleRequest() {
				if (!this.dataForm.id) delete(this.dataForm.id)
				const formMethod = this.dataForm.id ? Update : Create
				formMethod(this.dataForm).then(res => {
					uni.showToast({
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								uni.$emit('refresh')
								uni.navigateBack()
							}, 1500)
						}
					})
				})
			},
			initData() {
				getGoodsList().then(res => {
					this.goodsOptions = res.data.list
				})
				getCustomerList().then(res => {
					this.customerOptions = res.data.list
				})
			},
			selfInit() {
				this.addGoods()
				this.addPlan()
			},
			onChange(e) {
				const user = e[0]
				this.dataForm.salesmanName = user.fullName
			},
			addGoods() {
				const item = {
					goodsId: '',
					goodsCode: '',
					goodsName: '',
					specifications: '',
					unit: '',
					qty: '',
					price: '',
					amount: '',
					discount: null,
					cess: null,
					actualPrice: '',
					actualAmount: '',
					description: ''
				}
				this.dataForm.goodsList.push(item)
			},
			delGoods(index) {
				this.dataForm.goodsList.splice(index, 1)
			},
			addPlan() {
				const item = {
					receivableDate: '',
					receivableRate: '',
					receivableMoney: '',
					receivableMode: '',
					abstract: ''
				}
				this.dataForm.collectionPlanList.push(item)
			},
			delPlan(index) {
				this.dataForm.collectionPlanList.splice(index, 1)
			},
			onGoodsChange(e, i) {
				const goods = e[0]
				this.dataForm.goodsList[i] = {
					goodsId: goods.id,
					goodsCode: goods.code,
					goodsName: goods.text,
					specifications: goods.specifications,
					unit: goods.unit,
					qty: 1,
					price: goods.price,
					amount: goods.price,
					discount: 100,
					cess: 0,
					actualPrice: goods.price,
					actualAmount: goods.price,
					description: ''
				}
				this.$forceUpdate()
			},
			onCustomerChange(e) {
				const customer = e[0]
				this.dataForm.customerName = customer.text
			},
			count(row) {
				//金额 = 数量*单价
				row.amount = this.jnpf.toDecimal(parseFloat(row.price) * parseFloat(row.qty))
				//折扣价 = (单价*折扣)
				var discountPrice = row.price * (row.discount / 100);
				//实际单价 = 折扣价 * (1 + (税率 / 100))
				row.actualPrice = this.jnpf.toDecimal(discountPrice * (1 + (row.cess / 100)));
				//实际金额
				row.actualAmount = this.jnpf.toDecimal(parseFloat(row.actualPrice) * parseFloat(row
					.qty))
				this.$forceUpdate()
			}
		}
	}
</script>